kotlin null safety

大象笔记 > 标签 > kotlin null safety

Type mismatch: inferred type is Double? but Double was expected

写了一段 Android Koltin 的代码,做浮点数计算。但是编译时报错: Type mismatch: inferred type is Double? but Double was expected 出错的代码如下,出错是 try body 那行: fun calc(a: Double?, b: Double?, c: Double?): String { var result = 0.0 try { result = a * b / c } catch (e: Exception) { ...

阅读全文...